package jpal.collect;

import java.util.ArrayList;
//import java.util.LinkedList;
import java.util.Random;

import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;

import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
import com.carrotsearch.junitbenchmarks.BenchmarkRule;
import com.carrotsearch.junitbenchmarks.annotation.AxisRange;
import com.carrotsearch.junitbenchmarks.annotation.BenchmarkHistoryChart;
import com.carrotsearch.junitbenchmarks.annotation.LabelType;
import com.google.common.collect.Lists;

@BenchmarkOptions(callgc = true, benchmarkRounds = 1, warmupRounds = 0)
@AxisRange(min = 0, max = 15)
@BenchmarkHistoryChart(filePrefix = "RankListBenchmarkAdd", labelWith = LabelType.CUSTOM_KEY)
public class RankListBenchmarkAdd {

	@Rule
	public TestRule rule = new BenchmarkRule();

	final private RankList<Integer> rankList = RankList.create();
	final private ArrayList<Integer> arrayList = Lists.newArrayList();
//	final private LinkedList<Integer> linkedList = Lists.newLinkedList();
	final private Random r1 = new Random(NUM_ELEMENTS);
	final private Random r2 = new Random(NUM_ELEMENTS);
//	final private Random r3 = new Random(NUM_ELEMENTS);
	final private static int NUM_ELEMENTS = 1000;

	@BeforeClass
	public static void beforeClass() {
		System.setProperty("jub.consumers", "CONSOLE, H2");
		System.setProperty("jub.db.file", "charts/.benchmark");
		System.setProperty("jub.charts.dir", "charts");
		System.setProperty("jub.customkey", Integer.toString(NUM_ELEMENTS));
	}

	@Test
	public void benchmarkRankListAdd() {
		for (int i = 1; i <= NUM_ELEMENTS; i++)
			rankList.add(r1.nextInt(i), i);
	}

	@Test
	public void benchmarkArrayListAdd() {
		for (int i = 1; i <= NUM_ELEMENTS; i++)
			arrayList.add(r2.nextInt(i), i);
	}
	
//	@Test
//	public void benchmarkLinkedListAdd() {
//		for (int i = 1; i <= NUM_ELEMENTS; i++)
//			linkedList.add(r3.nextInt(i), i);
//	}

}
